package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.mvp.model.FindNewsModel;
import com.luck.easyfoodbatch.util.HttpUtil;
import com.luck.easyfoodbatch.util.Tools;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/8/12
 */
public class LatestInformationAdapter extends RecyclerArrayAdapter<FindNewsModel.DataBean.ModelsBean> {
    private Context mContext;

    public LatestInformationAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new CouponViewHolder(parent);
    }

    public class CouponViewHolder extends BaseViewHolder<FindNewsModel.DataBean.ModelsBean> {
        ImageView iv_banner;
        TextView tv_title, tv_time;

        public CouponViewHolder(ViewGroup parent) {
            super(parent, R.layout.information_item);
            iv_banner = $(R.id.iv_banner);
            tv_title = $(R.id.tv_title);
            tv_time = $(R.id.tv_time);
        }

        @Override
        public void setData(final FindNewsModel.DataBean.ModelsBean bean, int position) {
            Glide.with(mContext)
                    .load(HttpUtil.IMG_BASE_URL + bean.getImage())
                    .centerCrop()
                    .placeholder(R.mipmap.loading_16b9)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(iv_banner);
            tv_title.setText(bean.getTitle());
            if (!Tools.isNull(bean.getCreated_at())) {
                tv_time.setText(Tools.SubTime3(bean.getCreated_at() + ""));
            }
        }
    }
}
